package com.peng.leetcode.tree;

/**
 * BstToGst1
 * 1038. 从二叉搜索树到更大和树
 * https://leetcode.cn/problems/binary-search-tree-to-greater-sum-tree/
 *
 * @author: lupeng6
 * @create: 2023/2/8 19:16
 */
public class BstToGst1 {
    int sum = 0;

    public TreeNode bstToGst(TreeNode root) {
        if (root == null) {
            return null;
        }
        bstToGst(root.right);
        sum += root.val;
        root.val = sum;
        bstToGst(root.left);
        return root;
    }
}

